//
//  LoginController.swift
//  CarShare
//
//  Created by Pro on 2017/12/13.
//

import UIKit

class LoginController: BaseController {

    private lazy var loginViewModel = LoginViewModel()
    
    @IBOutlet weak var phoneTF: UITextField!
    @IBOutlet weak var passwordTF: UITextField!
    @IBOutlet weak var LoginBtn: UIButton!
    
    @IBOutlet weak var PushToRegistVCBtn: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white
        LoginBtn.backgroundColor = APPColor
        LoginBtn .setTitleColor(#colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), for: .normal)
        PushToRegistVCBtn.setTitleColor(APPColor, for: .normal)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    @IBAction func loginAction(_ sender: UIButton) {
        
       // 免登录
         navigationController?.pushViewController(HomeController(), animated: false)

         return
        
        let deviceID = UIDevice.current.identifierForVendor?.uuidString
            .replacingOccurrences(of: "-", with: "")
       
        let params = ["platform" : "ios",
                    "mobile_phone" : phoneTF.text ?? "",
                    "password" : passwordTF.text ?? "",
                    "lon" : "26.077012",// longitude,
                    "lat" : "114.815036",//latitude,
                    "device_id" : deviceID ?? "",
                    "is_driver" : 0] as [String : AnyObject]
        print(params)
        loginViewModel.requestLogin(para: params) { (success, msg) in
            
            if success {
                
                keyWindow?.rootViewController = BaseNavigationController(rootViewController: HomeController())
                
//            showProgressHUD(title: msg)
                
            } else {
                self.showError(msg)
            }
            
            
        }
    }
    
    
    @IBAction func RegisterAccountAction(_ sender: UIButton) {
        navigationController?.pushViewController(RegisterController(), animated: false)
    }
    
    
    
    @IBAction func ForgetPwdAction(_ sender: UIButton) {
        navigationController?.pushViewController(FogetPassWordController(), animated: false)
    }
}
